home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 November / CMCD1104.ISO / Software / Freeware / Programare / bluej / bluejsetup-200.exe / {app} / examples / people / Person.java < prev    next >
Encoding:
Text File  |  2004-09-15  |  1.2 KB  |  64 lines

  1. /**
  2.  * A person class for a simple BlueJ demo program. Person is used as
  3.  * an abstract superclass of more specific person classes.
  4.  *
  5.  * @author  Michael Kolling
  6.  * @version 1.0, January 1999
  7.  */
  8.  
  9. abstract class Person
  10. {
  11.     private String name;
  12.     private int yearOfBirth;
  13.  
  14.     /**
  15.      * Create a person with given name and age.
  16.      */
  17.     Person(String name, int yearOfBirth)
  18.     {
  19.         this.name = name;
  20.         this.yearOfBirth = yearOfBirth;
  21.     }
  22.  
  23.     /**
  24.      * Set a new name for this person.
  25.      */
  26.     public void setName(String newName)
  27.     {
  28.         name = newName;
  29.     }
  30.  
  31.     /**
  32.      * Return the name of this person.
  33.      */
  34.     public String getName()
  35.     {
  36.         return name;
  37.     }
  38.     
  39.     /**
  40.      * Set a new birth year for this person.
  41.      */
  42.     public void setYearOfBirth(int newYearOofBirth)
  43.     {
  44.         yearOfBirth = newYearOofBirth;
  45.     }
  46.  
  47.     /**
  48.      * Return the birth year of this person.
  49.      */
  50.     public int getYearOfBirth()
  51.     {
  52.         return yearOfBirth;
  53.     }
  54.  
  55.     /**
  56.      * Return a string representation of this object.
  57.      */
  58.     public String toString()    // redefined from "Object"
  59.     {
  60.         return "Name: " + name + "\n" +
  61.                "Year of birth: " + yearOfBirth + "\n";
  62.     }
  63. }
  64.